﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using IDAL.RF.ATETest;
using Model.RF.ATETest;

namespace BLL.RF.ATETest
{
    public class tb_result_DFL
    {
        private static readonly Itb_result_DFL dal = DALFactory.DataAccess.Createtb_result_DFL();
        /// <summary>
        /// 包括了电性能与互调数据
        /// </summary>
        /// <param name="sn"></param>
        /// <returns></returns>
        public IList<tb_result_DFL_Info> tb_result_DFL_GetbySN(string sn)
        {
            return dal.tb_result_DFL_GetbySN(sn);
        }
        /// <summary>
        /// 包括了电性能与互调数据
        /// </summary>
        /// <param name="dt1"></param>
        /// <param name="dt2"></param>
        /// <returns></returns>
        public IList<tb_result_DFL_Info> tb_result_DFL_GetbyDT(DateTime dt1, DateTime dt2)
        {
            return dal.tb_result_DFL_GetbyDT(dt1, dt2);
        }

        //以上为过滤后上传中兴的数据，以下为无过滤数据
        public IList<tb_result_DFL_Info> tb_result_DFL_GetbySN_withoutFilter(string sn)
        {
            return dal.tb_result_DFL_GetbySN_withoutFilter(sn);
        }

        public IList<tb_result_DFL_Info> tb_result_DFL_GetbyDT_withoutFilter(DateTime dt1, DateTime dt2)
        {
            return dal.tb_result_DFL_GetbyDT_withoutFilter(dt1, dt2);
        }

        public bool tb_ATETestAndItem_Insert(tb_result_DFL_Info ti, string productTypeID, List<tb_Param_DFL_Info> items)
        {
            DataTable itemdt = new DataTable();
            itemdt.Columns.Add(new DataColumn("Testequipid", Type.GetType("System.String")));
            itemdt.Columns.Add(new DataColumn("ProcessNum", Type.GetType("System.Int32")));
            itemdt.Columns.Add(new DataColumn("UnitName", Type.GetType("System.String")));
            itemdt.Columns.Add(new DataColumn("testtime", Type.GetType("System.DateTime")));
            itemdt.Columns.Add(new DataColumn("ParamName", Type.GetType("System.String")));
            itemdt.Columns.Add(new DataColumn("Res", Type.GetType("System.Int32")));
            itemdt.Columns.Add(new DataColumn("ResValue", Type.GetType("System.String")));
            itemdt.Columns.Add(new DataColumn("ResDesc", Type.GetType("System.String")));

            foreach (tb_Param_DFL_Info tii in items)
            {
                DataRow dr = itemdt.NewRow();
                dr["Testequipid"] = tii.Testequipid;
                dr["ProcessNum"] = tii.ProcessNum;
                dr["UnitName"] = tii.UnitName;
                dr["testtime"] = tii.testtime;
                dr["ParamName"] = tii.ParamName;
                dr["Res"] = tii.Res;
                dr["ResValue"] = tii.ResValue;
                dr["ResDesc"] = tii.ResDesc;
                itemdt.Rows.Add(dr);
            }
            return dal.tb_ATETestAndItem_Insert(ti, productTypeID, itemdt);
        }
    }
}
